package cn.uikit.demo.recyclerview.layoutManager

import android.os.Bundle
import android.util.Log
import android.view.View
import cn.uikit.demo.databinding.FragmentRecyclerViewBinding
import cn.uikit.demo.databinding.ItemCustomLayoutManagerBinding
import cn.uikit.demo.recyclerview.GridFragment.SpaceItemDecoration
import cn.uikit.demo.recyclerview.StackLayout
import sivin.uikit.adapter2.CommonAdapter
import sivin.uikit.adapter2.ItemViewDelegate
import sivin.uikit.adapter2.XViewHolder
import sivin.uikit.framework.BindingFragment

//自定义layoutManager的recyclerView
class CustomLMFragment : BindingFragment<FragmentRecyclerViewBinding>(
    FragmentRecyclerViewBinding::inflate
) {
    companion object {
        private const val TAG = "CustomLMFragment"
    }

    private val rvAdapter = CommonAdapter<String>().apply {
        addItemViewDelegate(object : ItemViewDelegate<String, ItemCustomLayoutManagerBinding>(
            ItemCustomLayoutManagerBinding::inflate
        ) {
            override fun onCreateViewHolder(
                binding: ItemCustomLayoutManagerBinding,
                viewType: Int
            ): XViewHolder<ItemCustomLayoutManagerBinding> {
                Log.d(TAG, "onCreateViewHolder: ")
                return super.onCreateViewHolder(binding, viewType)
            }

            override fun isForViewType(item: String, position: Int): Boolean {
                return true
            }

            override fun onBindData(
                holder: XViewHolder<ItemCustomLayoutManagerBinding>,
                item: String,
                position: Int
            ) {

            }

        })
    }

    private val dataList by lazy {
        val list = ArrayList<String>()
        for (i in 0 until 50) {
            list.add("测试---${i}")
        }
        list
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        binding.rv.apply {
            adapter = rvAdapter
            layoutManager = StackLayout(context)
        }
        rvAdapter.setDataList(dataList)
    }
}